<!DOCTYPE html>
<html>

<head>
    <title>审批角色管理</title>
    <my_css>
        <link rel="stylesheet" href="/jstree/themes/default/style.css" />
    </my_css>
</head>

<body>

<div class="page-header">
    <h1>${_resource_name!''}
        <small><i class="ace-icon fa fa-angle-double-right"></i>
            数据字典管理
        </small>
    </h1>
</div><!-- /.page-header -->

<div class="row">
    <div class="col-xs-12">
        <!-- PAGE CONTENT BEGINS -->

        <div class="col-sm-3">
            <div class="widget-box widget-color-green2">
                <div class="widget-header">
                    <h4 class="widget-title lighter smaller">
                        数据字典
                        <span class="smaller-80">(节点右击操作)</span>
                    </h4>
                </div>

                <div class="widget-body">
                    <div class="widget-main padding-8">
                        <div id="commonCdTree"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-9">
            <div class="widget-box widget-color-orange">
                <div class="widget-header">
                    <h4 class="widget-title lighter smaller" id="regit_div_id">
                        编辑
                    </h4>
                </div>
                <div class="widget-body">
                    <div class="widget-main">
                        <form id="common_form" class="form-horizontal" role="form" action="#" method="post">
                            <@form_input l="childCd" id="childCd" name="childCd" val="ROOT"/>
                            <@form_input l="childCdNm" id="childCdNm" name="childCdNm" val="根目录" />
                            <@form_input l="parentCd" id="parentCd" name="parentCd" val="#" readonly = "readonly"/>
                            <div class="clearfix form-actions">
                                <div class="col-md-offset-3 col-md-9">
                                    <button class="btn btn-info" type="submit" disabled=true>
                                        <i class="ace-icon fa fa-check bigger-110"></i> Submit
                                    </button>
                                    &nbsp; &nbsp; &nbsp;
                                    <button class="btn" type="reset" disabled=true>
                                        <i class="ace-icon fa fa-undo bigger-110"></i> Reset
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <!-- PAGE CONTENT ENDS -->
    </div><!-- /.col -->
</div><!-- /.row -->

</body>
<my_script>
    <script src="/assets/js/jquery.validate.min.js"></script>
    <script src="/common/js/jquery.validate.default.js"></script>
    <script src="/common/js/common.form.js"></script>
    <script src="/jstree/jstree.js"></script>
    <!-- bootbox scripts -->
    <script src="/common/js/bootbox.js"></script>
    <!-- inline scripts related to this page -->
    <script type="text/javascript">
        $(function(){
            $.post("${ctlKey}/findCommonCdTree", function(data){
                if(data.success) {
                    initJsTree(data.data)
                } else {
                    bootbox.dialog({
                        title: '出错了',
                        message: '<p><i class="fa fa-bomb"></i>' + data.message + '</p>'
                    });
                }
            },"json");
        });

        function initJsTree(nodeTree){
            $('#commonCdTree').jstree({
                "themes" : {
                    "variant" : "large",//加大
                    "ellipsis" : true //文字多时省略
                },
                'core': {
                    'data': nodeTree
                },
                "contextmenu":{
                    onContextMenu: function(e) {

                    },
                    select_node:false,
                    show_at_node:true,
                    items:{
                        "添加":{
                            "label":"添加",
                            "icon"				: "glyphicon glyphicon-plus",
                            "action":function(data){
                                var inst = $.jstree.reference(data.reference),
                                    obj = inst.get_node(data.reference);
                                console.log(obj.id);
                                inst.deselect_all();
                                inst.select_node(obj);

                                $("#common_form").attr("action",ctlKey + "/addSave");
                                $("#childCd").val("");
                                $("#childCdNm").val("");
                                $("#parentCd").val(obj.id);
                                $("#regit_div_id").text("添加");
                                $("button[type=submit]").removeAttr("disabled");
                                $("button[type=reset]").removeAttr("disabled");

                            }
                        },
                        "编辑":{
                            "separator_before"	: false,
                            "separator_after"	: false,
                            "_disabled"			: false, //(this.check("rename_node", data.reference, this.get_parent(data.reference), "")),
                            "label"				: "编辑",
                            "shortcut_label"	: 'F2',
                            "icon"				: "glyphicon glyphicon-leaf",
                            "action"			: function (data) {
                                var inst = $.jstree.reference(data.reference),
                                    obj = inst.get_node(data.reference);

                                inst.deselect_all();
                                inst.select_node(obj);
                                $("#childCd").val(obj.id);
                                $("#childCdNm").val(obj.text);
                                $("#parentCd").val(obj.parent);
                                $("#regit_div_id").text("编辑");
                                if ("ROOT" == obj.id) {
                                    $("button[type=submit]").attr("disabled", true);
                                    $("button[type=reset]").attr("disabled", true);
                                } else {
                                    $("#common_form").attr("action",ctlKey + "/update");
                                    $("button[type=submit]").removeAttr("disabled");
                                    $("button[type=reset]").removeAttr("disabled");
                                }
                            }
                        },
                        "删除":{
                            "separator_before"	: false,
                            "icon"				: false,
                            "separator_after"	: false,
                            "_disabled"			: false, //(this.check("delete_node", data.reference, this.get_parent(data.reference), "")),
                            "label"				: "删除",
                            "icon"				:"glyphicon glyphicon-remove",
                            "action"			: function (data) {
                                var inst = $.jstree.reference(data.reference),
                                    obj = inst.get_node(data.reference);
                                if ("ROOT" == obj.id) {
                                    bootbox.alert('根目录不能删除!');
                                } else {
                                    bootbox.confirm("确认删除此节点吗, 子节点会一并删除 ?",function(r){
                                        if(r) {
                                            $.post(ctlKey + "/delete/" + obj.id, function(deleteData){
                                                if (deleteData.success) {
                                                    location.href=ctlKey;
                                                } else {
                                                    bootbox.dialog({
                                                        title: '出错了',
                                                        message: '<p><i class="fa fa-bomb"></i>' + deleteData.message + '</p>'
                                                    });
                                                }
                                            });
                                        }
                                    });
                                }

                            }
                        }
                    }
                },

                "plugins" : ["contextmenu", "type","themes" ]
            });
        }
        function submitHandler(){
            ctlKey = "/admin/common-cd";
            return true;
        }
    </script>
</my_script>

</html>